<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Resources\GoodsResource;
use Illuminate\Http\Request;
use App\Models\Author;
use App\Http\Resources\AuthorResource;
use App\Http\Resources\AuthorSelfResource;
use App\Http\Queries\AuthorQuery;
class AuthorController extends Controller
{
    public function index(Request $request,AuthorQuery $query){
        //
        $page_size = $request->page_size?$request->page_size:9;
        AuthorResource::wrap("data");
        $authors = $query->where("is_show",true)->paginate($page_size);
        return AuthorResource::collection($authors);
    }

    public function show(int $author_id,AuthorQuery $query){
        $author = $query->findOrFail($author_id);
        return new AuthorSelfResource($author);
    }

    public function goods(Author $author,Request $request){
        $page_size = $request->page_size?$request->page_size:10;
         return GoodsResource::collection($author->goods()->paginate($page_size));
    }
}
